package com.android.questions.ui.adapter;

import android.annotation.SuppressLint;
import android.view.View;

import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;

import com.android.base.util.ActivityClickUtil;
import com.android.questions.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hx.currency.data.qa.model.QAIncome;
import com.liys.view.LineProView;

/**
 * FileName: CowAdapter
 * Author: admin
 * Date: 2021/11/4 15:07
 * Description:
 */
public class CowAdapter extends BaseQuickAdapter<QAIncome, BaseViewHolder> {
    private OnItemChildClickLister clickLister;

    public CowAdapter() {
        super(R.layout.item_cow);
        ActivityClickUtil.getInstance().clear();
    }

    @Override
    protected int getDefItemViewType(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(final BaseViewHolder baseViewHolder, QAIncome item) {
        AppCompatTextView tvTitle = baseViewHolder.getView(R.id.item_title);
        AppCompatTextView tvCash = baseViewHolder.getView(R.id.item_cash);
        LineProView progress = baseViewHolder.getView(R.id.item_progress);
        AppCompatTextView tvProgress = baseViewHolder.getView(R.id.item_tv_progress);
        AppCompatImageView ivReceive = baseViewHolder.getView(R.id.item_receive);

        tvCash.setText(item.getSa() + "元");

        double pb = item.getPb();

        progress.setProgress(pb);
        tvProgress.setText(pb + "%");

        int state = item.getSs();
        if (state == 0) {
            tvTitle.setText("观看广告提升进度");
            ivReceive.setEnabled(true);
            ivReceive.setImageResource(R.drawable.icon_increase_progress);
        } else if (state == 1) {
            tvTitle.setText("可以提现至微信");
            ivReceive.setEnabled(true);
            ivReceive.setImageResource(R.drawable.icon_waiting_withdraw);
        } else {
            tvTitle.setText("已成功提现至微信");
            ivReceive.setEnabled(false);
            ivReceive.setImageResource(R.drawable.icon_invite_withdrawal_complete);
        }

        ivReceive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ActivityClickUtil.getInstance().isFastClick()) {
                    //防止用户快速点击
                    return;
                }
                if (state == 0) {
                    if (clickLister != null) {
                        clickLister.onIncrease();
                    }
                } else if (state == 1) {
                    if (clickLister != null) {
                        clickLister.onWithdrawal(item);
                    }
                }
            }
        });
    }

    public OnItemChildClickLister getClickLister() {
        return clickLister;
    }

    public void setClickLister(OnItemChildClickLister clickLister) {
        this.clickLister = clickLister;
    }

    public interface OnItemChildClickLister {
        void onWithdrawal(QAIncome item);

        void onIncrease();
    }
}